package com.nextbus.main;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.SearchRecentSuggestions;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.nextbus.adapter.ToggleModeAdapter;
import com.nextbus.database.DatabaseHelper;
import com.nextbus.model.ToggleModeLineInfo;
import com.nextbus.provider.MySuggestionProvider;
import com.nextbus.transit.TransitSource;
import com.nextbus.transit.TransitSystem;
import com.nextbus.ui.BusOverlay;
import com.nextbus.ui.MyOverlay;
public class Main extends MapActivity {
	
    private static final String TAG = "Main";    
    private static final String selectedRouteIndexKey="selectedRouteIndexKey";
    private static final String selectedDirectionIndexkey="selectedDirectionIndexkey";
    
    //--------------------------------- 控件声明--------------------------------
    MapView mapView;

    EditText editText_searchRoute;

    ImageButton btn_searchRoute;

    ProgressBar pgsBar_updateStatus;

    ProgressDialog pgsDialog_updateStatus;

    // ----------------------------------Spinner start-------------------------------
    Spinner spr_toggleMode;

    // spinner对应的常量
    public static final int BUS_ALL = 0;
    
    public static final int BUS_PREDICTIONS_ONE = 1;
    
    public static final int STOP_PREDICTIONS_ONE = 2;
    
    public static final int STOP_PREDICTIONS_FAVORITE = 3;

    // 视图模式默认为2，即显示站点列表
    private int viewMode = 0;
    
    public static final String[] toggleModeText;

    public static final int[] toggleModeIcons;

    public static final int[] toggleMode = { 0, 1, 2, 3 };

    static {
        toggleModeText = new String[4];
        toggleModeText[0] = "显示所有车辆<未实现>";
        toggleModeText[1] = "当前路上的车";
        toggleModeText[2] = "当前站点和预测信息";
        toggleModeText[3] = "收藏的站点";
        toggleModeIcons = new int[] { R.drawable.bus_all, R.drawable.bus_one,
                R.drawable.busstop_one, R.drawable.busstop_star };
    }

    // ----------------------------------Spinner over-------------------------------



    // ---------------------------------MapView related--------------------------
    private MapController mapController;

    private LocationManager locationManager;

    private static GeoPoint boston = new GeoPoint(TransitSystem.BOSTON_LAT_INT,TransitSystem.BOSTON_LON_INT);

    // ---------------------------------图层变量---------------------------------
    private BusOverlay busOverlay;
    private BusOverlay stopOverlay;
    
    public static int BUSOVERLAY_STYLE = 1;
    public static int STOPOVERLAY_STYLE = 2;
    
    
    
    // ---------------------------------局部变量，暂时寄存之用-------------------
    
    private List<String> allRouteTags;
    
    private List<String> directionsWithSpecificRouteTag;

    private String routetag = "751";

    private String directiondir = "751_1_var0";

    private SearchRecentSuggestions suggestions;

    // ---------------------------------地图中需要的变量------------------------------------

    private MyOverlay myLocationOverlay;

    private MyOverlay searchOverlay;

    private Location myLocation;

    private Location placeLocation;

    private String provider;


    // ---------------------------------全局变量--------------------------
    DatabaseHelper databaseHelper;

    UpdateHandler updateHandler;
    
    UpdateAsyncTask updateTask;

    SharedPreferences prefs;
    
    Context context;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        

        // 取得view的引用
        setupViews();
        // 初始化系统
        initSystem();     
    }

    public void setupViews() {
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setStreetView(true);

        editText_searchRoute = (EditText) findViewById(R.id.searchTextView);
        editText_searchRoute.setText(routetag);
        editText_searchRoute.setOnClickListener(new Main1(Main.this));
        btn_searchRoute = (ImageButton) findViewById(R.id.searchButton);
        btn_searchRoute.setOnClickListener(new Main1(Main.this));

        spr_toggleMode = (Spinner) findViewById(R.id.predictionsOrLocations);
        spr_toggleMode.setAdapter(getToggleModeSpinner());
        // 响应spinner点击事件
        itemclick();

        // 显示进度控件
        pgsBar_updateStatus = (ProgressBar) findViewById(R.id.progress);
        pgsBar_updateStatus.setVisibility(View.INVISIBLE);
        
        pgsDialog_updateStatus = new ProgressDialog(this);
        pgsDialog_updateStatus.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pgsDialog_updateStatus.setTitle("Decompress the data");

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        mapController = mapView.getController();
        mapView.setBuiltInZoomControls(true);

   
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        provider = locationManager.getBestProvider(criteria, true);
        Drawable drawable = getResources().getDrawable(R.drawable.busstop_t);
        myLocationOverlay = new MyOverlay(drawable,this);
        searchOverlay = new MyOverlay(drawable, this);

        suggestions = new SearchRecentSuggestions(this,
                MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
        
        //赋值路线列表
        allRouteTags=TransitSource.allRouteTags;

    }

    public void initSystem() {
    	//取得当前上下文
        context = getApplicationContext();
        // 实例化dbHelper
        databaseHelper = new DatabaseHelper(context);
        // 程序自检，是否安装
        updateTask = new UpdateAsyncTask(context, pgsDialog_updateStatus);

        Log.d(TAG, "before check");
        // 首先检测手机是否有相同的数据库，若没有认为是第一次安装，设置isFirstInstall为true
        boolean isDBInstall = updateTask.isDBInstall();
        boolean checkFreeSpace = updateTask.checkFreeSpace();
        Log.d(TAG, isDBInstall + "       " + checkFreeSpace);
        if (!isDBInstall && checkFreeSpace) {
            // 进行数据的初始化工作,将该操作放到后台去操作
            Log.d(TAG, "in if");
            updateTask.setProgress(pgsDialog_updateStatus);
            updateTask.runInstallDB();
        }
     
        // 取得SharedPreferences中的静态参数
        prefs = PreferenceManager.getDefaultSharedPreferences(this);

        // 取得上次软件的运行参数
        boolean runInBackgroundKey = prefs.getBoolean("runInBackgroundKey",true);
        boolean showUnpredictableBusesKey = prefs.getBoolean("showUnpredictableBusesKey", false);
        boolean hideCircleCheckboxKey = prefs.getBoolean("hideCircleCheckboxKey", false);
        boolean showRouteLineKey = prefs.getBoolean("showRouteLine", true);
        
        routetag = prefs.getString(selectedRouteIndexKey, routetag);
        directiondir = prefs.getString(selectedDirectionIndexkey, directiondir);
        
        int viewModeKey = prefs.getInt("viewModeKey", -1);
        int latKey = prefs.getInt("latKey", Integer.MAX_VALUE);
        int lonKey = prefs.getInt("lonKey", Integer.MAX_VALUE);
        int zoomlevelKey = prefs.getInt("zoomlevelKey", 13);
        
        editText_searchRoute.setText(routetag+" "+directiondir);
        
        // 恢复上次软件运行状态
        // 恢复spinner
        viewMode = (viewModeKey == -1) ? 0 : viewModeKey;
        spr_toggleMode.setSelection(viewMode);
        
        // 恢复搜索框
        editText_searchRoute.setText("Route " + routetag);
        
        // 定位地图中心
        if (latKey != Integer.MAX_VALUE && lonKey != Integer.MAX_VALUE) {
            mapController.animateTo(new GeoPoint(latKey, lonKey));
        } else {
            mapController.animateTo(boston);
        }
        
        // 取得图层中的图标资源
        Drawable busIcon = getApplication().getResources().getDrawable(R.drawable.bus);
        Drawable stopIcon = getApplication().getResources().getDrawable(R.drawable.busstop);
        Drawable arrow=getApplication().getResources().getDrawable(R.drawable.arrow);
        
        busOverlay =  new BusOverlay(busIcon,mapView,this,viewMode,arrow);
        stopOverlay = new BusOverlay(stopIcon,mapView,this,viewMode);

        mapView.invalidate();
        // 根据上次运行路线，及视图模式恢复软件上次运行状态
        updateHandler = new UpdateHandler(context, mapView, pgsDialog_updateStatus, routetag, viewModeKey,
                runInBackgroundKey, showUnpredictableBusesKey,hideCircleCheckboxKey, showRouteLineKey, 
                busOverlay, busIcon, stopOverlay, stopIcon,directiondir,pgsBar_updateStatus,editText_searchRoute);
        
        // 恢复上次运行的状态
        updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_RESUME_LAST_RUN_STATE);
    }

    // 响应spinner点击事件
    public void itemclick() {
        spr_toggleMode.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                switch (arg2) {
                case BUS_ALL:
                	System.out.println("spinner0被点击");
                    break;
                case BUS_PREDICTIONS_ONE:
                	System.out.println("------------------------------------->Bus_Prediciton被点击");
                    if(viewMode !=  BUS_PREDICTIONS_ONE) {
                        viewMode = BUS_PREDICTIONS_ONE;
                        updateHandler.setViewMode(viewMode); 
                        updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
                        boolean flag = updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
                        if (flag == false) {
                            Log.d(TAG, "@itemclick 出错了");
                        } 
                    }
                    break;
                case STOP_PREDICTIONS_ONE:
                    if (viewMode != STOP_PREDICTIONS_ONE) {
                        viewMode = STOP_PREDICTIONS_ONE;
                        updateHandler.setViewMode(viewMode);            
                        updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
                        boolean flag = updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
                        if(flag == false) {
                            Log.d(TAG, "@itemclick 出错了");
                        } 
                    }
                    break;
                case STOP_PREDICTIONS_FAVORITE:
                    break;
                default:
                    break;
                }
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });
    }

    /**
     * 加载menu.xml
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu, menu);
        return true;
    }

    /**
     * 处理相关的menu事件
     */
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        super.onMenuItemSelected(featureId, item);
        switch (item.getItemId()) {
        case R.id.centerOnLocationMenuItem://找到当前用户位置
            findMyLocation();
            break;
        case R.id.chooseStop://搜索地点
            getplace();
            break;
        case R.id.centerOnBostonMenuItem://定位到波士顿
            locateBoston();
            break;
        case R.id.settingsMenuItem://设置选项
            startActivity(new Intent(Main.this, Preferences.class));
            break;
        case R.id.chooseRoute:// 在路线列表中选择一条路线
            chooseRoute();
            break;
        case R.id.refreshItem://手动刷新界面
            refresh();
            break;
        }
        return true;
    }

    // --------------定位到当前位置----------------------------
    public void findMyLocation() {
        mapView.getOverlays().clear();
        // 用于用户的定位，这个函数我们定位在只有当经纬度发生一定变化时才调用，在一定范围内就可以更新
        //最小时间间隔是3秒，最小距离间隔是0米
        locationManager.requestLocationUpdates(provider, 3000, 0,new MyLocationListener());
    }

    // -----------------输入地名获得坐标位置---------------------------------------------
    // ????需要完善
    public void getplace() {
    	System.out.println("Main.getplace()");
        final EditText theDestination = new EditText(this);
        // placeLocation=new Location(provider);
        new AlertDialog.Builder(this)
                .setTitle("请输入")
                .setIcon(android.R.drawable.ic_dialog_info)
                .setView(theDestination)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        String destination = theDestination.getText()
                                .toString();
                        searchName(destination);
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                    }
                }).show();
    }

    // -------------------通过地名查找----------------------------------------------
    public void searchName(String destination) {// 输入的目的地,根据地址来获得地址信息，经纬度等等
        mapView.getOverlays().clear();
        System.out.println("Main.searchName()");
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        List<Address> addresses;
        try {
            addresses = geocoder.getFromLocationName(destination, 1);
            System.out.println(addresses.size() + 1000);
            if (addresses.size() != 0) {
                GeoPoint searchpoint = new GeoPoint((int) (addresses.get(0)
                        .getLatitude() * 1000000), (int) (addresses.get(0)
                        .getLongitude() * 1000000));
                OverlayItem overlayitem = new OverlayItem(searchpoint,
                        addresses.get(0).getCountryName(), addresses.get(0)
                                .getFeatureName()
                                + addresses.get(0).getPostalCode());
                searchOverlay.addOverlay(overlayitem);
                mapView.getOverlays().add(searchOverlay);
                mapController.animateTo(searchpoint); 
                mapController.setZoom(10);
                mapController.setCenter(searchpoint);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //  cxd ----------------选择一条路线和一个方向---------------------------------------------------
    public void chooseRoute() {
        new AlertDialog.Builder(Main.this)
                .setTitle(R.string.alert_title_route)
                .setAdapter(
                        new ArrayAdapter<String>(Main.this, 
                        						R.layout.item,
                        						R.id.textViewId, 
                        						allRouteTags),
                        new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,int which) {
                            	routetag=allRouteTags.get(which);
                            	showDirectionlist();
                        	
                            }
                        }).show();
    }


    // 点击路线以后显示方向列表
    private void showDirectionlist() {
    	directionsWithSpecificRouteTag = databaseHelper.getDirectionsNameList(routetag);
    	new AlertDialog.Builder(Main.this)                              
    					.setTitle("选择方向")
				        .setAdapter(
				                new ArrayAdapter<String>(
				                        Main.this,
				                        R.layout.item,
				                        R.id.textViewId,
				                        (directionsWithSpecificRouteTag = 
				                        databaseHelper.getDirectionsNameList(routetag))),
				                new OnClickListener() {
				                    @Override
				                    public void onClick(DialogInterface dialog,int which) {
				                        // 把当前选择的方向保存下来
				                        directiondir = directionsWithSpecificRouteTag.get(which);
				                        //把当前方向写在搜索框中
				                        editText_searchRoute.setText(directiondir);
				                        // 显示车站信息
				                        updateHandler.setRoute(routetag);
				                        updateHandler.setDirection(directiondir);
				                        showRouteorBus();
				                    }
				                }).show();
	}
    
   
    // 用于弹出对话框点击相应方向之后，首先要判断当前spinner的模式，再转到handler中
    
    public void showRouteorBus()
    {       
        updateHandler.setRoute(routetag);
        updateHandler.setDirection(directiondir);
        if (Main.STOP_PREDICTIONS_ONE == viewMode) {
            updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_PRESS_STOP);
            updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_PRESS_STOP);
            suggestions .saveRecentQuery( routetag + " "  + directiondir, null);
        }
        if (Main.BUS_PREDICTIONS_ONE == viewMode) {
            System.out.println("xiaobai ceshi ");
            updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_PRESS_BUS);
            updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_PRESS_BUS);      
            suggestions .saveRecentQuery( routetag + " "  + directiondir, null);
        }
        
    }
    
    // ------------------------定位到boston-----------------------------------
    public void locateBoston() {
        if (mapView != null) {
            GeoPoint gp = new GeoPoint(TransitSystem.BOSTON_LAT_INT,TransitSystem.BOSTON_LON_INT);
            mapView.getController().animateTo(gp);
        } else {
            Log.d(TAG, "mapView is null.. Dangerous..");
        }
    }


    // ---------------------------------更新-------------------------------------------
    public void refresh() {
        if (TransitSystem.currentTimeMillis() - updateHandler.getLastUpdateTime() < 10000) {
            Toast.makeText(Main.this, "Please wait 10 seconds before click again",
                Toast.LENGTH_LONG).show();
        } else {
        	updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
            updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_CHANGE_VIEWMODE);
        }
        updateHandler.setLastUpdateTime(TransitSystem.currentTimeMillis());
    }

    /**
     * 获取Adapter for Toggle Mode Spinner
     */
    private SpinnerAdapter getToggleModeSpinner() {
        ArrayList<ToggleModeLineInfo> modeList = new ArrayList<ToggleModeLineInfo>();
        int length = toggleMode.length;
        for (int i = 0; i < length; i++) {
            int j = toggleModeIcons[i];
            String str = toggleModeText[i];
            ToggleModeLineInfo lineInfo = new ToggleModeLineInfo(j, str);
            modeList.add(lineInfo);
        }
        return new ToggleModeAdapter(this, modeList);
    }

    /**
     * 现在搜索框里还只能实现两种搜索，一种是点击保存下来的条目，还有一钟就是仅仅输入路线名字
     * SearchDialog invoke to create intent 1. get query (route info) 2. add
     * Recent Query Suggestions
     */
    @Override
    public void onNewIntent(Intent intent) {
        Log.d(TAG, "on new Intent");
        super.onNewIntent(intent);
        setIntent(intent);
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            SearchRecentSuggestions suggestions = new SearchRecentSuggestions(
                    this, MySuggestionProvider.AUTHORITY,
                    MySuggestionProvider.MODE);
            // if query exists saveQuery
            suggestions.saveRecentQuery(query, null);
            Log.d(TAG, "save intent");
            
            // else do nothing
            // ----------提取搜索框中的数据--------------------------------------------
            String tmpRoute = "";
            String tmpDirection = "";
            int index = query.indexOf(" ");
            //搜索路线方向
            if (index > 0) {
                tmpRoute = query.substring(0,index);
                tmpDirection = query.substring(index+1);
                routetag=tmpRoute;
                directiondir=tmpDirection;
                //点击搜索框里面的条目之后开始显示路线
                showRouteorBus();
            } 
            //用户搜索路线
            else if (TransitSource.allRouteTags.contains(query) && tmpDirection == "") {
                tmpRoute = query;
                routetag=tmpRoute;
                showDirectionlist();
            }else {
				Toast.makeText(context, "没有该路线,请重新输入", Toast.LENGTH_LONG).show();
			}
        }
    }
    
    protected boolean isRouteDisplayed() {
        return false;
    }
     /**
     * dxt  用于定位用户当前坐标
     */
    //内部类此处设置为私有内部类
    private class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location location) {
            double lon = 0, lat = 0;
            lon = location.getLongitude();
            lat = location.getLatitude();
            System.out.println("当前我的纬度  " + location.getLongitude());
            System.out.println("当前我的经度  " + location.getLatitude());

            GeoPoint point = new GeoPoint((int) (lat * 1E6),(int) (lon * 1E6));
            System.out.println(point);
            OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!","I'm in Mexico City!");
            myLocationOverlay.addOverlay(overlayitem);
            mapView.getOverlays().add(myLocationOverlay);
            mapController.animateTo(point);
            mapController.setZoom(10);
            mapController.setCenter(point);

        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

    }
   
    /*
     * xxq 当主界面失去焦点或是关闭软件，都会调用onPause，所以在里面更新动态参数显得合适不过
     * 
     * 每次暂停的时候都经过一个保存参数的函数，那么软件 退出后在进来像路线，方向这些就是上次的了
     */
    protected void onPause() {
        if (mapView != null && prefs != null) {
            Editor editor = prefs.edit();

            GeoPoint gp = mapView.getMapCenter();

            editor.putInt("viewModeKey", viewMode);
            editor.putInt("latKey", gp.getLatitudeE6());
            editor.putInt("lonKey", gp.getLongitudeE6());
            editor.putInt("zoomlevelKey", mapView.getZoomLevel());
            
    		editor.putString(selectedRouteIndexKey, routetag);
    		editor.putString(selectedDirectionIndexkey, directiondir);
    		editor.commit();
        }
        super.onPause();
    }
    
    //  dxt   返回主界面的时候，我们每次都先读设置中的一些参数，使得参数更改都
    @Override
	protected void onResume() {
		// TODO Auto-generated method stub
    	populateHandlerSettings();
    	//设置过后立马发送一次消息,使得设置之后的东西马上有效
    	updateHandler.removeMessages(TransitSystem.OPERATION_TYPE_UPDATE_INSTANT);
    	updateHandler.sendEmptyMessage(TransitSystem.OPERATION_TYPE_UPDATE_INSTANT);
    	
		super.onResume();
	}

	// --------------------退出界面时关闭数据库-----------------------------------------------------
    protected void onDestroy() {
        // TODO Auto-generated method stub    	
        super.onDestroy();
    }
    
    private void populateHandlerSettings() {
    	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    	
    	boolean runInBackgroundCheckboxValue = prefs.getBoolean(getString(R.string.runInBackgroundCheckbox), true);
    	updateHandler.setUpdateConstant(runInBackgroundCheckboxValue);
    	updateHandler.setShowUnpredictableBus(prefs.getBoolean(getString(R.string.showUnpredictableBusesCheckbox), false));
    	updateHandler.setHideBlueCircle(prefs.getBoolean(getString(R.string.hideCircleCheckbox), false));
    	updateHandler.setShowRoutePath(prefs.getBoolean(getString(R.string.showRouteLineCheckbox), false));
    }
}